home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1024 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  743 b 

  1. Path: crl.crl.com!not-for-mail
  2. From: bobfry@crl.com (Robert Fry)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Bit Masking
  5. Date: 10 Jan 1996 16:09:10 -0800
  6. Organization: CRL Dialup Internet Access
  7. Message-ID: <4d1kf7$ffu@crl.crl.com>
  8. References: <DKz5y4.8En@twisto.eng.hou.compaq.com>
  9. NNTP-Posting-Host: crl.com
  10.  
  11. garyc%cs%contractors@bangate.compaq.com (Gary Clarke) writes:
  12.  
  13. >Can someone tell me the elegent way to clear specific bits from a
  14. >byte, e.g.
  15.  
  16. ># define BIT_1    1
  17. ># define BIT_2    2
  18. ># define BIT_3    4
  19. ># define BIT_4    8
  20.  
  21. >Set the bit:    x |= BIT_x
  22.  
  23. >Clear the bit using BIT_x:    ????
  24.  
  25. Most people I know use: x &= ~BIT_x
  26.  
  27. Be careful of data item size problems, however. Not all compilers will 
  28. generate the code you want when x is not an int.
  29.  
  30. Bob
  31.